package com.fbinggun.fbinggunutil.gui;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

/**
 * 请勿使用
 */
public class GuiListener implements Listener {

    @EventHandler
    public void on(InventoryClickEvent event) {
        if (event.getClickedInventory() == null) {
            return;
        }
        Player player = (Player) event.getWhoClicked();
        Inventory inventory = player.getOpenInventory().getTopInventory();
        if (inventory != null && inventory.getHolder() instanceof FHolder) {
            FHolder fHolder = (FHolder) inventory.getHolder();
            if (fHolder.getGui().isCancelPlayerInvCancel()) {
                event.setCancelled(true);
            }
        }
        if (event.getClickedInventory().getHolder() != null ) {
            if (event.getClickedInventory().getHolder() instanceof FHolder) {
                FHolder fHolder = (FHolder) event.getClickedInventory().getHolder();
                fHolder.getGui().run(event, fHolder);
            }
        }
    }


}
